<?php

/**
 * Created by PhpStorm.
 * User: sunshine
 * Date: 17-5-2
 * Time: 下午11:25
 */
namespace Home\Model;

use Think\Model;

class UserLoginLogModel extends Model
{
    protected $tableName = 'user_cookie';

    public function getLog($uid, $index){
        if ($index == -1){
            $result = $this->where('uid ='.(string)$uid)->count();
        }else {
            $result = $this->order('id desc')->field('uid,userIp,userLoginTime,userLogoutTime')->where('uid = ' . (string)$uid)->limit($index*10,10)->select();
        }
        return $result;
    }
}

class UserModel extends Model
{
    public function getLog($uid, $index){
        $userloginlogmodel = new UserLoginLogModel();
        $result = $userloginlogmodel->getLog($uid, $index);
        if($result){
            $returnArr = array(
                'status' => true,
                'info' => $result
            );
        }else{
            $returnArr = array(
                'status' => false,
                'errcode'=>107,
                'errmsg'=>'read error'
            );
        }
        return $returnArr;
    }
}